package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * The type Shopping cart controller.
 */
@Api(tags = "购物车相关接口")
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/user/shoppingCart")
@RestController
public class ShoppingCartController {

    private final ShoppingCartService shoppingCartService;

    /**
     * 添加购物车接口
     *
     * @param shoppingCartDTO the shopping cart dto
     * @return the result
     */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<?> addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }


    /**
     * 查看购物车中的菜品或套餐
     *
     * @return the result
     */
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getList() {
        List<ShoppingCart> shoppingCarts = shoppingCartService.getList();
        return Result.success(shoppingCarts);
    }

    /**
     * 删除购物车中的菜品或套餐
     *
     * @return the result
     */
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result<?> deleteShoppingCart() {
        shoppingCartService.delete();
        return Result.success();
    }


    /**
     * 删除购物车中一个商品
     *
     * @return the result
     */
    @ApiOperation("删除购物车中一个商品")
    @PostMapping("/sub")
    public Result<?> deleteByCondition(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.deleteByCondition(shoppingCartDTO);
        return Result.success();
    }


}
